var dayTimes = {};
var timesSelect = "";

createSelectedOption(new Date(0,0,0,0,0,0,0));

function getDayTimes(){
	return dayTimes;
}

function getTimeSelect(){
	return timesSelect;
}

function createSelectedOption(fecha){
	var hours = 7;
	var minutes = fecha.getMinutes();
	var j = "";
	timesSelect += "<option value='null'></option>";
	for(var i = 0;i<1025;i+=5){
		var showHours = "";
		var showMinutes = "";
		if(hours.toString().length==1){
			showHours = "0"+hours;
		}else{
			showHours = hours;
		}
		if(minutes.toString().length==1){
			showMinutes = "0"+minutes;
		}else{
			showMinutes = minutes;
		}
		j = showHours + ":" + showMinutes;
		timesSelect += "<option value='"+j+"'>"+j+"</option>";
		if(minutes==55){
			minutes = 0;
			hours += 1;
		}else{
			minutes+=5;
		}
		if(hours==24){
			hours = 0;
		}
	}
} 

function showDayTime(val){
	switch(val)
	{
	case 1:
		if($("#lunesTime").is(':visible')){
			$("#lunesTime").hide();
		}else{
			$("#lunesTime").show();
		}	
	  break;
	case 2:
		if($("#martesTime").is(':visible')){
			$("#martesTime").hide();
		}else{
			$("#martesTime").show();
		}	
	  break;
	case 3:
		if($("#miercolesTime").is(':visible')){
			$("#miercolesTime").hide();
		}else{
			$("#miercolesTime").show();
		}	
	  break;
	case 4:
		if($("#juevesTime").is(':visible')){
			$("#juevesTime").hide();
		}else{
			$("#juevesTime").show();
		}	
	  break;
	case 5:
		if($("#viernesTime").is(':visible')){
			$("#viernesTime").hide();
		}else{
			$("#viernesTime").show();
		}	
	  break;
	case 6:
		if($("#sabadoTime").is(':visible')){
			$("#sabadoTime").hide();
		}else{
			$("#sabadoTime").show();
		}	
	  break;
	default:
	  //alert("algo anda mal");
		$("#dialogSomthingError").dialog();
	}
}

function sendDayTime(){
	var lunesTimeStart = $("#lunesTimeStart").val();
	var lunesTimeEnd = $("#lunesTimeEnd").val();
	var martesTimeStart = $("#martesTimeStart").val();
	var martesTimeEnd = $("#martesTimeEnd").val();
	var miercolesTimeStart = $("#miercolesTimeStart").val();
	var miercolesTimeEnd = $("#miercolesTimeEnd").val();
	var juevesTimeStart = $("#juevesTimeStart").val();
	var juevesTimeEnd = $("#juevesTimeEnd").val();
	var viernesTimeStart = $("#viernesTimeStart").val();
	var viernesTimeEnd = $("#viernesTimeEnd").val();
	var sabadoTimeStart = $("#sabadoTimeStart").val();
	var sabadoTimeEnd = $("#sabadoTimeEnd").val();

	if(lunesTimeStart=="null" || lunesTimeEnd=="null"){
		dayTimes["1"] = null;
	}else{
		dayTimes["1"] = lunesTimeStart+";"+lunesTimeEnd;
	}
	if(martesTimeStart=="null" || martesTimeEnd=="null"){
		dayTimes["2"] = null;
	}else{
		dayTimes["2"] = martesTimeStart+";"+martesTimeEnd;
	}
	if(miercolesTimeStart=="null" || miercolesTimeEnd=="null"){
		dayTimes["3"] = null;
	}else{
		dayTimes["3"] = miercolesTimeStart+";"+miercolesTimeEnd;
	}
	if(juevesTimeStart=="null" || juevesTimeEnd=="null"){
		dayTimes["4"] = null;
	}else{
		dayTimes["4"] = juevesTimeStart+";"+juevesTimeEnd;
	}
	if(viernesTimeStart=="null" || viernesTimeEnd=="null"){
		dayTimes["5"] = null;
	}else{
		dayTimes["5"] = viernesTimeStart+";"+viernesTimeEnd;
	}
	if(sabadoTimeStart=="null" || sabadoTimeEnd=="null"){
		dayTimes["6"] = null;
	}else{
		dayTimes["6"] = sabadoTimeStart+";"+sabadoTimeEnd;
	}
//	if(getWhereAmI()==1){
//		alert(JSON.stringify(dayTimes));
//	}
	hideDayTime();
}

function hideDayTime(){
	$("#lunesTime").hide();
	$("#martesTime").hide();
	$("#miercolesTime").hide();
	$("#juevesTime").hide();
	$("#viernesTime").hide();
	$("#sabadoTime").hide();
}